<template>
    <view>
        <view :style="{ height: windowHeight }"
            style="display: flex; align-items: center; justify-content: center;">
            <!-- <div id="center">
                <div class="skype-loader">
                    <div class="dot">
                        <div class="first"></div>
                    </div>
                    <div class="dot"></div>
                    <div class="dot"></div>
                    <div class="dot"></div>
                </div>
                Logging in...
            </div> -->
        </view>
    </view>
</template>

<script>
	import { gettwotokenBPMtoken} from '@/workspaces/api/framework/service.js';
    export default {
        data() {
            return {
				locationhref: "",
                windowHeight: '100%',
                oaconfig: {},
                tenancyId: '',
                isloading: '',
                billName: '',
                billNo: '',
                appKey: '',
                appSecret: '',
                deviceInfo: {}
            };
        },
        onLoad() {
            let that = this;
            that.oaconfig = that.$oaconfig;
            uni.getSystemInfo({
                success: function(res) {
                    that.windowHeight = res.windowHeight + 'px';
                }
            });
            //获取设备信息
            //this.deviceInfo = uni.getSystemInfoSync();
            that.getTokenlogin();
            //setTimeout(function() {
            //}, 1000);
        },
        methods: {
            getTokenlogin() {
                let _this = this;
                _this.locationhref = window.location.href;
                let location_ddCode = "";
                //_this.locationhref = 'http://localhost:8089?ssotoken=2e29ad7f98334ea68c660ac7ebd710a8&webpath=/workflow/businessMP/workflowform?formAction=2&appId=AP&wiid=54275bc3-fab9-4bf5-ad67-1d8219036c16&taskId=361bdee9-376c-401c-b280-55a1abeb607f';
				_this.tenancyId = "BPM";
                //获取当前皮肤背景
                let background = '';
                if (background) {
                    _this.$oaconfig.backgroundColor = background;
                }else{
                    _this.$oaconfig.backgroundColor = "#3296fa";
                }
                if (_this.locationhref.split('?')[1] && _this.locationhref.indexOf('ssotoken') > 0) {
					let ssotoken= "";
					if(_this.locationhref.indexOf('appId') > 0) {//待办跳转
						ssotoken= _this.locationhref.split('ssotoken=')[1].split('&webpath')[0];
					} else {//正常单点
						ssotoken= _this.locationhref.split('ssotoken=')[1];
					}
                    _this.mplogin(ssotoken);
                } else {
                    uni.reLaunch({
                    	url: '../../views/login/login'
                    });
                }
            },
            //mp登录
            mplogin(token) {
                let that = this;
                if (token) {
					that.$api.setUserInfo({ token: token })
                    that.$lyRequest.get('/gateway/basedata/mp/dbsap/trip/sysUser/appUserInfo.do', {}).then(result => {
						if (result.data && result.data.result == 1) {
							// 登陆成功之后，缓存用户信息，跳转到审批页面
							result.data.ly_id = result.data.rows.userid;
							result.data.ly_loginname = result.data.rows.username;
							result.data.rows.token = token;
							that.$api.setUserInfo(result.data.rows);
							gettwotokenBPMtoken({
								tenancyId: 'BPM',
								mptoken: token
							}).then(res => {
								if (res.success) {
									result.data.rows.token= res.data.token;
									that.$store.commit('user', result.data.rows)
									that.$store.commit('loginauthor', result.data.rows)
									uni.setStorageSync('login_type', 'local')
									if(that.locationhref.indexOf('appId') > 0){
										var url = __webpath + that.locationhref.split('webpath=')[1];
										console.log(url)
										FUI.Window.ngto(url);
									}else{
										if (that.remember_box) {
											var ase = that.$api.aesEncrypt(JSON.stringify(e.detail.value), 'mplanyou07558888');
											uni.setStorageSync('remember_key', ase);
										} else {
											uni.removeStorageSync('remember_key');
										}
										uni.reLaunch({
											url: '../index/index'
										});
									}
								}else{
									that.$store.commit('logout');
									that.handleLoginUnSuccess(result, username);
								}
							}).catch(e => {
								that.$api.showModalWithCloseButton(e.message);
							});
						} else {
							uni.reLaunch({
								url: '../../views/login/login'
							});
						}
					})
					.catch(() => {
						uni.reLaunch({
							url: '../../views/login/login'
						});
					});
                } else {
                    uni.reLaunch({
                        url: '../../views/login/login'
                    });
                }
            }
        }
    };
</script>

<style lang="scss">
    page {
        background-color: #fffbfb !important;
    }
    
    #center {
        position: absolute;
        top: 50%;
        left: 50%;
        margin-top: -360upx;
        margin-left: -150upx;
        width: 300upx;
        height: 160upx;
        font-family: 'Lato', sans-serif;
        font-weight: bold;
        font-size: 32upx;
        color: #f01e1e;
        text-align: center;
        -webkit-font-smoothing: antialiased;
    }
    
    .skype-loader {
        width: 160upx;
        height: 160upx;
        position: relative;
        margin: auto;
        margin-top: 60px;
        margin-bottom: 70px;
    }
    
    .skype-loader .dot {
        position: absolute;
        top: 0;
        left: 0;
        width: 160upx;
        height: 160upx;
        background-color: rgba(0, 0, 0, 0);
        animation: 1.7s dotrotate cubic-bezier(0.775, 0.005, 0.31, 1) infinite;
    }
    
    .skype-loader .dot:nth-child(1) {
        animation-delay: 0.2s;
    }
    
    .skype-loader .dot:nth-child(2) {
        animation-delay: 0.35s;
    }
    
    .skype-loader .dot:nth-child(3) {
        animation-delay: 0.45s;
    }
    
    .skype-loader .dot:nth-child(4) {
        animation-delay: 0.55s;
    }
    
    .skype-loader .dot:after,
    .skype-loader .dot .first {
        content: '';
        position: absolute;
        width: 16upx;
        height: 16upx;
        background: #f01e1e;
        border-radius: 50%;
        left: 50%;
        margin-left: -8upx;
    }
    
    .skype-loader .dot .first {
        background: #f01e1e;
        margin-top: -8upx;
        animation: 1.7s dotscale cubic-bezier(0.775, 0.005, 0.31, 1) infinite;
        animation-delay: 0.2s;
    }
    
    @keyframes dotrotate {
        from {
            transform: rotate(0deg);
        }
    
        to {
            transform: rotate(360deg);
        }
    }
    
    @keyframes dotscale {
    
        0%,
        10% {
            width: 32upx;
            height: 32upx;
            margin-left: -16upx;
            margin-top: -8upx;
        }
    
        50% {
            width: 16upx;
            height: 16upx;
            margin-left: -8px;
            margin-top: 0;
        }
    
        90%,
        100% {
            width: 32upx;
            height: 32upx;
            margin-left: -16upx;
            margin-top: -8px;
        }
    }
</style>
